<?php
include("../connection/connection.php");
include("reportFunctions.php");
$distId=$_REQUEST['distId'];
$sqlReport = "SELECT distinct `district_id`,`district_name`,`block_id`,`block_name` FROM `tbl_lookup_location` where `district_id` = ".$distId." group by `block_id`";
$queryReport = mysql_query($sqlReport);
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Block</title>
</head>
<body>
<table border="0" width="900" cellspacing="0" cellpadding="0">
	<tr>
		<td bgcolor="#E9E9E9" height="26">
		<p align="center"><span style="font-size: 9pt; font-weight: 700">
		<font face="Verdana" color="#224568">Percentage of schemes where preventive maintenance is in place </font></span>
		
		</td>
	</tr>
	<tr>
		<td bgcolor="#E9E9E9" height="56">
		<table border="1" width="900" cellspacing="0" cellpadding="0" height="47" bgcolor="#C5D8EB">
			<tr>
				<td width="80" align="center">
				<font face="Verdana" style="font-size: 8.5pt"><b>Name of Block</b></font></td>
				<td width="41" align="center">
				<p align="center"><font face="Verdana" style="font-size: 8.5pt">
				<b>Type of Scheme</b></font></td>
				<td width="60" align="center">
				<font style="font-size: 8.5pt" face="Verdana"><b>Total no. of Schemes (No.)</b></font></td>
				<td width="70" align="center">
				<font style="font-size: 8.5pt" face="Verdana"><b>Total no. of schemes with preventive maintenance mechanism (No.)</b> </font></td>
				<td width="60" align="center">
				<font style="font-size: 8.5pt" face="Verdana"><b>Percent of scheme with preventive mechanism (%)</b></font></td>
			</tr>
            <?php
			//$numVillage=0;
			//$numFormVill=0;
			while($rowReport = mysql_fetch_array($queryReport)) {
			
				 $a1=getSchemeNoBlockWise($distId,'Piped',$rowReport['block_id']);
				 $a2=getSchemeNoBlockWise($distId,'P&T',$rowReport['block_id'])+getSchemeNoBlockWise($distId,'TSS(P&T)',$rowReport['block_id']);
				 $a3=getSchemeNoBlockWise($distId,'Sanitary Diggs',$rowReport['block_id']);
				 $a4=getSchemeNoBlockWise($distId,'HP',$rowReport['block_id']);
				 $c1=$a1+$a2+$a3+$a4;
				
				 $a6=getpreventivepiped($rowReport['block_id'],'Piped');
				 $a7=getpreventivepiped($rowReport['block_id'],'P&T')+getpreventivepiped($rowReport['block_id'],'TSS(P&T)');
				 $a8=getpreventivepiped($rowReport['block_id'],'Sanitary Diggs');
				 $a9=getpreventivehp($rowReport['block_id']);
				 $c2=$a6+$a7+$a8+$a9;
				 
				 ?>  
				<tr bgcolor="#FFFFFF">
				
				<td width="" rowspan="4" align="center"><font face="Verdana" style="font-size: 8.5pt"><?php echo $rowReport['block_name'];  ?></font></td>
				<td align="left" width=""><font face="Verdana" style="font-size: 8.5pt">Piped</font></td>
				<td width="" align="center"><font face="Verdana" style="font-size: 8.5pt"><?php echo getSchemeNoBlockWise($distId,'Piped',$rowReport['block_id']);  ?></font></td>
				<td width="" align="center"><font face="Verdana" style="font-size: 8.5pt"><?php echo getpreventivepiped($rowReport['block_id'],'Piped');  ?></font></td>
				<td width="" align="center"><font face="Verdana" style="font-size: 8.5pt">
				<?php
				if($a1==0)
				{
				echo "0.00";
				}else{
				echo number_format(($a6/$a1)*100,2,'.','');
				}				
				?></font>
				</td>
			    </tr>
				<tr bgcolor="#FFFFFF">
				  <td align="left"><font face="Verdana" style="font-size: 8.5pt">P&T</font></td>
		          <td width="" align="center"><font face="Verdana" style="font-size: 8.5pt"><?php echo getSchemeNoBlockWise($distId,'P&T',$rowReport['block_id'])+getSchemeNoBlockWise($distId,'TSS(P&T)',$rowReport['block_id']);?></font></td>
		          <td width="" align="center"><font face="Verdana" style="font-size: 8.5pt"><?php echo getpreventivepiped($rowReport['block_id'],'P&T')+getpreventivepiped($rowReport['block_id'],'TSS(P&T)');  ?></font></td>
		          <td width="" align="center"><font face="Verdana" style="font-size: 8.5pt">
				  <?php
				if($a2==0)
				{
				echo "0.00";
				}else{
				echo number_format(($a7/$a2)*100,2,'.','');
				}				
				?></font>
				  </td>
		  </tr>
				<tr bgcolor="#FFFFFF">
				  <td align="left"><font face="Verdana" style="font-size: 8.5pt">Sanitary Diggs</font></td>
		          <td width="" align="center"><font face="Verdana" style="font-size: 8.5pt"><?php echo getSchemeNoBlockWise($distId,'Sanitary Diggs',$rowReport['block_id']);?></font></td>
		          <td width="" align="center"><font face="Verdana" style="font-size: 8.5pt"><?php echo getpreventivepiped($rowReport['block_id'],'Sanitary Diggs');  ?></font></td>
		          <td width="" align="center"><font face="Verdana" style="font-size: 8.5pt">
				  <?php
				if($a3==0)
				{
				echo "0.00";
				}else{
				echo number_format(($a8/$a3)*100,2,'.','');
				}				
				?></font>
				  </td>
		  </tr>
				<tr bgcolor="#FFFFFF">
				  <td align="left"><font face="Verdana" style="font-size: 8.5pt">HP</font></td>
		          <td width="" align="center"><font face="Verdana" style="font-size: 8.5pt"><?php echo getSchemeNoBlockWise($distId,'HP',$rowReport['block_id']);?></font></td>
		          <td width="" align="center"><font face="Verdana" style="font-size: 8.5pt"><?php echo getpreventivehp($rowReport['block_id']);  ?></font></td>
		          <td width="" align="center"><font face="Verdana" style="font-size: 8.5pt">
				   <?php
				if($a4==0)
				{
				echo "0.00";
				}else{
				echo number_format(($a9/$a4)*100,2,'.','');
				}				
				?></font>
				  </td>
		  </tr>
			<tr bgcolor="#E9E9E9">
				<td width="" align="center">&nbsp;</td>
				<td width="" align="left"><font face="Verdana" style="font-size: 8.5pt"><b>Total</b></font></td>
				<td align="center" width=""><font face="Verdana" style="font-size: 8.5pt"><b><?php echo $c1;?></b></font></td>
				<td align="center" width=""><font face="Verdana" style="font-size: 8.5pt"><b><?php echo $c2;?></b></font></td>
				<td align="center" width=""><font face="Verdana" style="font-size: 8.5pt"><b>
				<?php
				if($c1==0)
				{
				echo "0.00";
				}else{
				echo number_format(($c2/$c1)*100,2,'.','');
				}	
				?></b></font>
				</td>
			</tr>
			
				 <?php
				 $gran_tot_scheme+=$c1;
				 $gran_tot_pm+=$c2;	
         	}
			?>
			<tr bgcolor="#E9E9E9">
				<td width="" align="center">&nbsp;</td>
				<td width="" align="left"><font face="Verdana" style="font-size: 8.5pt"><b>Grand Total</b></font></td>
				<td align="center" width=""><font face="Verdana" style="font-size: 8.5pt"><b><?php echo $gran_tot_scheme;?></b></font></td>
				<td align="center" width=""><font face="Verdana" style="font-size: 8.5pt"><b><?php echo $gran_tot_pm;?></b></font></td>
				<td align="center" width=""><font face="Verdana" style="font-size: 8.5pt"><b>
				<?php
				if($gran_tot_scheme==0)
				{
				echo "0.00";
				}else{
				echo number_format(($gran_tot_pm/$gran_tot_scheme)*100,2,'.','');
				}	
				?></b></font>
				</td>
			</tr>	
				
		</table>
		</td>
	</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>



</body>

</html>
	
